﻿@{
    ViewBag.Title = "MKAdmin管理系统";
    Layout = "/Views/Shared/_Layout.cshtml";
}
@using MKAdminCore.DTO.Web.Common
@using MKAdminCore.ToolKit.Config

@model UserInfo

@section Styles {
    <link href="@PageCssFilesConfig.Home" rel="stylesheet" />
    <link href="@PageCssFilesConfig.HighLighterShCore" rel="stylesheet" />
    <link href="@PageCssFilesConfig.HighLighterShThemeDefault" rel="stylesheet" />
}
<form class="layui-form" lay-filter="lf_form_home_index">
    <div class="main-layout" id='main-layout'>
        <!--侧边栏-->
        <div class="main-layout-side">
            <div class="m-logo zf-logo">
                <img src="~/Images/indexLogo.png" alt="Alternate Text" />
            </div>
            <ul class="layui-nav layui-nav-tree" lay-filter="leftNav"></ul>
        </div>
        <!--右侧内容-->
        <div class="main-layout-container">
            <!--头部-->
            <div class="main-layout-header">
                <div class="menu-btn" id="hideBtn">
                    <a href="javascript:;">
                        <span class="iconfont">&#xe60e;</span>
                    </a>
                </div>
                <ul class="layui-nav zf_top_nav_bg zf_Sign_out">
                    @*<li class="layui-nav-item">
                            <a href="javascript:;" class="nav-header-text" id="top_color_333" data-text="个人信息">@Model.OperatorName</a>
                            <i class="layui-icon layui-icon-triangle-d"></i>
                        </li>*@
                    <li class="layui-nav-item" style="margin-right: 15px;">
                        <a style="cursor:pointer" href="https://gitee.com/mikeworld/MKAdminCore" target="_blank"><span style="color:red">源码下载</span></a>
                    </li>
                    <li class="layui-nav-item" style="margin-right: 15px;">
                        <a style="cursor:context-menu">@Model.OperatorName</a>
                    </li>
                    <li class="layui-nav-item">
                        <a class="nav-header-text " id="top_color_333" href="/home/signout">退出</a>
                    </li>
                    @*<div class="zf_Sign_out_list">
                            <p class="zf_Sign_out_base">
                                <a class="nav-header-text" id="ChangePassword">个人设置</a>
                            </p>
                            <p>
                                <a class="nav-header-text" href="/home/signout">退出</a>
                            </p>
                        </div>*@
                </ul>

            </div>
            <!--主体内容-->
            <div class="main-layout-body">
                <!--tab 切换-->
                <div class="layui-tab layui-tab-brief main-layout-tab" lay-filter="tab" lay-allowClose="true">
                    <ul class="layui-tab-title">
                        <li class="layui-this welcome" lay-id='0'>首页</li>
                    </ul>
                    <ul class="layui-tab-code">
                        <li><img class="layui-tab-see-sound-code" title="查看源代码" src="/images/code.png" /></li>
                    </ul>
                    @*<div style="float:left">
                            <span>刷新</span>
                        </div>*@
                    <div class="layui-tab-content">
                        <div class="layui-tab-item layui-show" style="background: #f5f5f5;">
                            <!--1-->
                            <iframe src="/home/welcome" width="100%" height="100%" name="iframe" scrolling="auto" class="iframe" framborder="0"></iframe>
                            <!--1end-->
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-tab layui-tab-brief main-layout-tab" lay-filter="demo" id="cn_tab_view_soundcode" style="display:none">
            <ul class="layui-tab-title"></ul>
            <div class="layui-tab-content" style="overflow-x:scroll;">

            </div>
        </div>
    </div>
    <ul id="dlyMenuTab">
        <li class="dlyMenuTabli">关闭标签</li>
        <li style="border-bottom:1px solid #dbdbdb;"></li>
        <li class="dlyMenuTabli">关闭其他标签</li>
        <li class="dlyMenuTabli">关闭全部标签</li>
    </ul>
</form>
<script>
    //后期单独存放在一个文件里
    var reloadPage = function () {

        var nav_move = ('#main-layout .main-layout-side ul li .layui-nav-more');
        if ($(nav_move) == null || $(nav_move).length <= 0) {
            window.location.reload();
        }
    }

    var generateMenu = function (menuData) {
        var menuHtml = "";
        if (menuData !== null && menuData.length > 0) {
            var firstMenu = menuData.filter(function (item) {
                return item.rightParentId == -1;
            });
            if (firstMenu !== null && firstMenu.length > 0) {

                $.each(firstMenu, function (index, item) {
                    var menuUnfold = '';
                    //if (index == 0) {
                    //    menuUnfold = 'layui-nav-itemed';
                    //}
                    menuHtml += '<li class="layui-nav-item ' + menuUnfold + '">';
                    menuHtml += '   <a href="javascript:;"><i class="iconfont"><img src="' + item.iconName + '"/></i>' + item.rightName + '</a>';
                    menuHtml += '   <dl class="layui-nav-child">';

                    //查找二级菜单
                    var secondMenu = menuData.filter(function (secItem) {
                        return secItem.rightParentId == item.rightId;
                    });
                    if (secondMenu !== null && secondMenu.length > 0) {

                        $.each(secondMenu, function (index, item) {
                            menuHtml += '<dd><a href="javascript:;" data-url="' + item.menuPageUrl + '" data-id="' + item.rightId + '" data-text="' + item.rightName + '"><span class="zf_common_line_l"></span>' + item.rightName + '</a></dd>';
                        });
                    }

                    menuHtml += '   </dl>';
                    menuHtml += '</li>';
                });
            }
            $(".layui-nav-tree").append(menuHtml);

            //有时候左边菜单加载不出，这里检测到就重新刷新
            window.setTimeout(reloadPage, 1000);
        }

    }

    $.ajax({
        //需要同步请求，异步会有点问题
        async: false,
        url: '/organization/permissionsetting/permissionmenulist',
        type: 'Post',
        dataType: 'json',
        success: function (res) {
            //菜单权限
            var menuData = res.data.menuData;

            generateMenu(menuData);
        }
    });
</script>

@section Scripts {
    <script type="text/javascript" src="@PageJsFilesConfig.HomeIndex"></script>
    <script type="text/javascript" src="@PageJsFilesConfig.HighLighterShCore"></script>
    <script type="text/javascript" src="@PageJsFilesConfig.HighLighterShBrushBash"></script>
    <script type="text/javascript" src="@PageJsFilesConfig.HighLighterShBrushCss"></script>
    <script type="text/javascript" src="@PageJsFilesConfig.HighLighterShBrushCSharp"></script>
    <script type="text/javascript" src="@PageJsFilesConfig.HighLighterShBrushJScript"></script>
    <script type="text/javascript" src="@PageJsFilesConfig.HighLighterShBrushPlain"></script>
    <script type="text/javascript" src="@PageJsFilesConfig.HighLighterShBrushSql"></script>
    <script type="text/javascript" src="@PageJsFilesConfig.HighLighterShBrushXml"></script>
}